EC-CUBE 2.4.4
[ class tree: EC-CUBE 2.4.4 ] [ index: EC-CUBE 2.4.4 ] [ all elements ]

Source for file SC_CartSession.php

Documentation is available at SC_CartSession.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. /* カートセッション管理クラス */
  25. class SC_CartSession {
  26.     var $key;
  27.     var $key_tmp;    // ユニークIDを指定する。
  28.  
  29.     /* コンストラクタ */
  30.     function SC_CartSession($key 'cart'{
  31.         SC_Utils::sfDomainSessionStart();
  32.  
  33.         if($key == ""$key "cart";
  34.         $this->key = $key;
  35.     }
  36.  
  37.     // 商品購入処理中のロック
  38.     function saveCurrentCart($key_tmp{
  39.         $this->key_tmp = "savecart_" $key_tmp;
  40.         // すでに情報がなければ現状のカート情報を記録しておく
  41.         if(count($_SESSION[$this->key_tmp]== 0{
  42.             $_SESSION[$this->key_tmp$_SESSION[$this->key];
  43.         }
  44.         // 1世代古いコピー情報は、削除しておく
  45.         foreach($_SESSION as $key => $val{
  46.             if($key != $this->key_tmp && ereg("^savecart_"$key)) {
  47.                 unset($_SESSION[$key]);
  48.             }
  49.         }
  50.     }
  51.  
  52.     // 商品購入中の変更があったかをチェックする。
  53.     function getCancelPurchase({
  54.         $ret = isset($_SESSION[$this->key]['cancel_purchase'])
  55.             ? $_SESSION[$this->key]['cancel_purchase'"";
  56.         $_SESSION[$this->key]['cancel_purchase'false;
  57.         return $ret;
  58.     }
  59.  
  60.     // 購入処理中に商品に変更がなかったかを判定
  61.     function checkChangeCart({
  62.         $change false;
  63.         $max $this->getMax();
  64.         for($i 1$i <= $max$i++{
  65.             if ($_SESSION[$this->key][$i]['quantity'!= $_SESSION[$this->key_tmp][$i]['quantity']{
  66.                 $change true;
  67.                 break;
  68.             }
  69.             if ($_SESSION[$this->key][$i]['id'!= $_SESSION[$this->key_tmp][$i]['id']{
  70.                 $change true;
  71.                 break;
  72.             }
  73.         }
  74.         if ($change{
  75.             // 一時カートのクリア
  76.             unset($_SESSION[$this->key_tmp]);
  77.             $_SESSION[$this->key]['cancel_purchase'true;
  78.         else {
  79.             $_SESSION[$this->key]['cancel_purchase'false;
  80.         }
  81.         return $_SESSION[$this->key]['cancel_purchase'];
  82.     }
  83.  
  84.     // 次に割り当てるカートのIDを取得する
  85.     function getNextCartID({
  86.         foreach($_SESSION[$this->keyas $key => $val){
  87.             $arrRet[$_SESSION[$this->key][$key]['cart_no'];
  88.         }
  89.         return (max($arrRet1);
  90.     }
  91.  
  92.     // 商品ごとの合計価格
  93.     function getProductTotal($arrInfo$id{
  94.         $max $this->getMax();
  95.         for($i 0$i <= $max$i++{
  96.             if(isset($_SESSION[$this->key][$i]['id'])
  97.                && $_SESSION[$this->key][$i]['id'== $id{
  98.  
  99.                 // 税込み合計
  100.                 $price $_SESSION[$this->key][$i]['price'];
  101.                 $quantity $_SESSION[$this->key][$i]['quantity'];
  102.                 $pre_tax SC_Utils_Ex::sfPreTax($price$arrInfo['tax']$arrInfo['tax_rule']);
  103.                 $total $pre_tax $quantity;
  104.                 return $total;
  105.             }
  106.         }
  107.         return 0;
  108.     }
  109.  
  110.     // 値のセット
  111.     function setProductValue($id$key$val{
  112.         $max $this->getMax();
  113.         for($i 0$i <= $max$i++{
  114.             if(isset($_SESSION[$this->key][$i]['id'])
  115.                && $_SESSION[$this->key][$i]['id'== $id{
  116.                 $_SESSION[$this->key][$i][$key$val;
  117.             }
  118.         }
  119.     }
  120.  
  121.     // カート内商品の最大要素番号を取得する。
  122.     function getMax({
  123.         $cnt 0;
  124.         $pos 0;
  125.         $max 0;
  126.         if (count($_SESSION[$this->key]0){
  127.             foreach($_SESSION[$this->keyas $key => $val{
  128.                 if (is_numeric($key)) {
  129.                     if($max $key{
  130.                         $max $key;
  131.                     }
  132.                 }
  133.             }
  134.         }
  135.         return ($max);
  136.     }
  137.  
  138.     // カート内商品数の合計
  139.     function getTotalQuantity({
  140.         $total 0;
  141.         $max $this->getMax();
  142.         for($i 0$i <= $max$i++{
  143.             $total+= $_SESSION[$this->key][$i]['quantity'];
  144.         }
  145.         return $total;
  146.     }
  147.  
  148.  
  149.     // 全商品の合計価格
  150.     function getAllProductsTotal($arrInfo{
  151.         // 税込み合計
  152.         $total 0;
  153.         $max $this->getMax();
  154.         for($i 0$i <= $max$i++{
  155.  
  156.             if (!isset($_SESSION[$this->key][$i]['price'])) {
  157.                 $_SESSION[$this->key][$i]['price'"";
  158.             }
  159.             $price $_SESSION[$this->key][$i]['price'];
  160.  
  161.             if (!isset($_SESSION[$this->key][$i]['quantity'])) {
  162.                 $_SESSION[$this->key][$i]['quantity'"";
  163.             }
  164.             $quantity $_SESSION[$this->key][$i]['quantity'];
  165.  
  166.             $pre_tax SC_Utils::sfPreTax($price$arrInfo['tax']$arrInfo['tax_rule']);
  167.             $total+= ($pre_tax $quantity);
  168.         }
  169.         return $total;
  170.     }
  171.  
  172.     // 全商品の合計税金
  173.     function getAllProductsTax($arrInfo{
  174.         // 税合計
  175.         $total 0;
  176.         $max $this->getMax();
  177.         for($i 0$i <= $max$i++{
  178.             $price $_SESSION[$this->key][$i]['price'];
  179.             $quantity $_SESSION[$this->key][$i]['quantity'];
  180.             $tax SC_Utils_Ex::sfTax($price$arrInfo['tax']$arrInfo['tax_rule']);
  181.             $total+= ($tax $quantity);
  182.         }
  183.         return $total;
  184.     }
  185.  
  186.     // 全商品の合計ポイント
  187.     function getAllProductsPoint({
  188.         // ポイント合計
  189.         $total 0;
  190.         $max $this->getMax();
  191.         for($i 0$i <= $max$i++{
  192.             $price $_SESSION[$this->key][$i]['price'];
  193.             $quantity $_SESSION[$this->key][$i]['quantity'];
  194.  
  195.             if (!isset($_SESSION[$this->key][$i]['point_rate'])) {
  196.                 $_SESSION[$this->key][$i]['point_rate'"";
  197.             }
  198.             $point_rate $_SESSION[$this->key][$i]['point_rate'];
  199.  
  200.             if (!isset($_SESSION[$this->key][$i]['id'][0])) {
  201.                 $_SESSION[$this->key][$i]['id'][0"";
  202.             }
  203.             $id $_SESSION[$this->key][$i]['id'][0];
  204.             $point SC_Utils_Ex::sfPrePoint($price$point_ratePOINT_RULE$id);
  205.             $total+= ($point $quantity);
  206.         }
  207.         return $total;
  208.     }
  209.  
  210.     // カートへの商品追加
  211.     function addProduct($id$quantity$campaign_id ""{
  212.         $find false;
  213.         $max $this->getMax();
  214.         for($i 0$i <= $max$i++{
  215.  
  216.             if($_SESSION[$this->key][$i]['id'== $id{
  217.                 $val $_SESSION[$this->key][$i]['quantity'$quantity;
  218.                 if(strlen($val<= INT_LEN{
  219.                     $_SESSION[$this->key][$i]['quantity']+= $quantity;
  220.                     if(!empty($campaign_id)){
  221.                         $_SESSION[$this->key][$i]['campaign_id'$campaign_id;
  222.                         $_SESSION[$this->key][$i]['is_campaign'true;
  223.                     }
  224.                 }
  225.                 $find true;
  226.             }
  227.         }
  228.         if(!$find{
  229.             $_SESSION[$this->key][$max+1]['id'$id;
  230.             $_SESSION[$this->key][$max+1]['quantity'$quantity;
  231.             $_SESSION[$this->key][$max+1]['cart_no'$this->getNextCartID();
  232.             if(!empty($campaign_id)){
  233.                 $_SESSION[$this->key][$max+1]['campaign_id'$campaign_id;
  234.                 $_SESSION[$this->key][$max+1]['is_campaign'true;
  235.             }
  236.         }
  237.     }
  238.  
  239.     // 前頁のURLを記録しておく
  240.     function setPrevURL($url{
  241.         // 前頁として記録しないページを指定する。
  242.         $arrExclude array(
  243.             "detail_image.php",
  244.             "/shopping/"
  245.         );
  246.         $exclude false;
  247.         // ページチェックを行う。
  248.         foreach($arrExclude as $val{
  249.             if(ereg($val$url)) {
  250.                 $exclude true;
  251.                 break;
  252.             }
  253.         }
  254.         // 除外ページでない場合は、前頁として記録する。
  255.         if(!$exclude{
  256.             $_SESSION[$this->key]['prev_url'$url;
  257.         }
  258.     }
  259.  
  260.     // 前頁のURLを取得する
  261.     function getPrevURL({
  262.         return isset($_SESSION[$this->key]['prev_url'])
  263.             ? $_SESSION[$this->key]['prev_url'"";
  264.     }
  265.  
  266.     // キーが一致した商品の削除
  267.     function delProductKey($keyname$val{
  268.         $max count($_SESSION[$this->key]);
  269.         for($i 0$i $max$i++{
  270.             if($_SESSION[$this->key][$i][$keyname== $val{
  271.                 unset($_SESSION[$this->key][$i]);
  272.             }
  273.         }
  274.     }
  275.  
  276.     function setValue($key$val{
  277.         $_SESSION[$this->key][$key$val;
  278.     }
  279.  
  280.     function getValue($key{
  281.         return $_SESSION[$this->key][$key];
  282.     }
  283.  
  284.     function getCartList({
  285.         $max $this->getMax();
  286.         $arrRet array();
  287.         for($i 0$i <= $max$i++{
  288.             if(isset($_SESSION[$this->key][$i]['cart_no'])
  289.                && $_SESSION[$this->key][$i]['cart_no'!= ""{
  290.                 $arrRet[$_SESSION[$this->key][$i];
  291.             }
  292.         }
  293.         return $arrRet;
  294.     }
  295.  
  296.     // カート内にある商品IDを全て取得する
  297.     function getAllProductID({
  298.         $max $this->getMax();
  299.         for($i 0$i <= $max$i++{
  300.             if($_SESSION[$this->key][$i]['cart_no'!= ""{
  301.                 $arrRet[$_SESSION[$this->key][$i]['id'][0];
  302.             }
  303.         }
  304.         return $arrRet;
  305.     }
  306.  
  307.     function delAllProducts({
  308.         $max $this->getMax();
  309.         for($i 0$i <= $max$i++{
  310.             unset($_SESSION[$this->key][$i]);
  311.         }
  312.     }
  313.  
  314.     // 商品の削除
  315.     function delProduct($cart_no{
  316.         $max $this->getMax();
  317.         for($i 0$i <= $max$i++{
  318.             if($_SESSION[$this->key][$i]['cart_no'== $cart_no{
  319.                 unset($_SESSION[$this->key][$i]);
  320.             }
  321.         }
  322.     }
  323.  
  324.     // 個数の増加
  325.     function upQuantity($cart_no{
  326.         $max $this->getMax();
  327.         for($i 0$i <= $max$i++{
  328.             if($_SESSION[$this->key][$i]['cart_no'== $cart_no{
  329.                 if(strlen($_SESSION[$this->key][$i]['quantity'1<= INT_LEN{
  330.                     $_SESSION[$this->key][$i]['quantity']++;
  331.                 }
  332.             }
  333.         }
  334.     }
  335.  
  336.     // 個数の減少
  337.     function downQuantity($cart_no{
  338.         $max $this->getMax();
  339.         for($i 0$i <= $max$i++{
  340.             if($_SESSION[$this->key][$i]['cart_no'== $cart_no{
  341.                 if($_SESSION[$this->key][$i]['quantity'1{
  342.                     $_SESSION[$this->key][$i]['quantity']--;
  343.                 }
  344.             }
  345.         }
  346.     }
  347.  
  348.     // 全商品の合計送料
  349.     function getAllProductsDelivFee({
  350.         // ポイント合計
  351.         $total 0;
  352.         $max $this->getMax();
  353.         for($i 0$i <= $max$i++{
  354.             $deliv_fee $_SESSION[$this->key][$i]['deliv_fee'];
  355.             $quantity $_SESSION[$this->key][$i]['quantity'];
  356.             $total+= ($deliv_fee $quantity);
  357.         }
  358.         return $total;
  359.     }
  360.  
  361.     // カートの中の売り切れチェック
  362.     function chkSoldOut($arrCartList$is_mobile false){
  363.         foreach($arrCartList as $key => $val){
  364.             if($val['quantity'== 0){
  365.                 // 売り切れ商品をカートから削除する
  366.                 $this->delProduct($val['cart_no']);
  367.                 SC_Utils_Ex::sfDispSiteError(SOLD_OUT""true""$is_mobile);
  368.             }
  369.         }
  370.     }
  371.  
  372.     /**
  373.      * カートの中のキャンペーン商品のチェック
  374.      * @param integer $campaign_id キャンペーンID
  375.      * @return boolean True:キャンペーン商品有り False:キャンペーン商品無し
  376.      */
  377.     function chkCampaign($campaign_id){
  378.         $max $this->getMax();
  379.         for($i 0$i <= $max$i++{
  380.             if($_SESSION[$this->key][$i]['is_campaign'and $_SESSION[$this->key][$i]['campaign_id'== $campaign_idreturn true;
  381.         }
  382.  
  383.         return false;
  384.     }
  385.  
  386. }
  387. ?>

Documentation generated on Fri, 24 Feb 2012 13:59:59 +0900 by Seasoft